code vault - break apart delimited textWhat links here?

Header



class line_breaker {
    int     size;       // total number of array locations allocated
    int     next;       // next available location
    char  **array;
public:
            line_breaker(char *line, char* break_char);
           ~line_breaker();
    int     count() { return next; }
;
    char   *element(int i);
    char   *operator[] (unsigned i) { if (i < next) return array[i]; else return NULL; }
;
    void    dump(FILE *outfile);
};

Code

  1. include <string.h>
  2. include <stdio.h>
  3. include <stdlib.h>


  1. include "line_breaker.h"


//############################################################################## line_breaker::line_breaker(char *line, char *break_char) { next = 0; size = 100; array = new char *[size]; int i = 0; while (line[i] > '\0') { char temp[100]; int j = 0; while (line[i] > '\0' && !strchr(break_char, line[i])) { temp[j++] = line[i++]; } temp[j] = '\0'; array[next] = strdup(temp); next ++;

if (strchr(break_char, line[i])) i++; } // for (i = 0; i < next; i++) { // printf("%4d: %s\n", i + 1, array[i]); // } }

//############################################################################## line_breaker::~line_breaker() { for (int i = 0; i < next; i++) { delete array[i]; } }

//############################################################################## char *line_breaker::element(int i) { if (i < next) { return array[i]; } return NULL; }

//############################################################################## void line_breaker::dump(FILE *outfile) { for (int i = 0; i < next; i++) { fprintf(outfile, "%4d: %s\n", i + 1, array[i]); } }



code vault - break apart delimited text
filename:code vault - break apart delimited text
filename:code%20vault%20%2D%20break%20apart%20delimited%20text
last edit:March 26 2009 18:30:06 (5519 days ago)
ct = 1714966801.000000 = May 05 2024 23:40:01
ft = 1238106606.000000 = March 26 2009 18:30:06
dt = 476860195.000000